﻿#include "mainwindow.h"
#include "./ui_mainwindow.h"
#include <QButtonGroup>

MainWindow::MainWindow(QWidget *parent)
    : QMainWindow(parent)
    , ui(new Ui::MainWindow)
    , homePage(new HomePage(this))
    , extractPage(new ExtractPage(this))
{
    ui->setupUi(this);
    setupUI();
    initPages();
    createConnections();
}

MainWindow::~MainWindow()
{
    delete ui;
}

void MainWindow::setupUI()
{
    // 设置窗口标题
    setWindowTitle(tr("ExtractCore"));
    
    // 设置按钮组
    QButtonGroup *buttonGroup = new QButtonGroup(this);
    buttonGroup->addButton(ui->homeButton);
    buttonGroup->addButton(ui->extractButton);
    buttonGroup->addButton(ui->settingsButton);
    
    // 设置按钮可选中
    ui->homeButton->setCheckable(true);
    ui->extractButton->setCheckable(true);
    ui->settingsButton->setCheckable(true);
    
    // 默认选中首页按钮
    ui->homeButton->setChecked(true);
}

void MainWindow::createConnections()
{
    connect(ui->homeButton, &QToolButton::clicked, this, &MainWindow::onHomeButtonClicked);
    connect(ui->extractButton, &QToolButton::clicked, this, &MainWindow::onExtractButtonClicked);
    connect(ui->settingsButton, &QToolButton::clicked, this, &MainWindow::onSettingsButtonClicked);
}

void MainWindow::initPages()
{
    // 添加首页
    ui->stackedWidget->addWidget(homePage);
    ui->stackedWidget->addWidget(extractPage);
    ui->stackedWidget->setCurrentWidget(homePage);
}

void MainWindow::onHomeButtonClicked()
{
    ui->stackedWidget->setCurrentWidget(homePage);
}

void MainWindow::onExtractButtonClicked()
{
    ui->stackedWidget->setCurrentWidget(extractPage);
}

void MainWindow::onSettingsButtonClicked()
{
    // TODO: 切换到设置页面
} 
